home *** CD-ROM | disk | FTP | other *** search
- Path: noc.netcom.net!news
- From: Tarang Deshpande <tarang@willows.com>
- Newsgroups: comp.lang.c
- Subject: Re: === **ptr HELP ===
- Date: Thu, 18 Apr 1996 12:07:14 -0700
- Organization: NETCOM Network Operations
- Message-ID: <317692E2.6D0F@willows.com>
- References: <31765AA6.41C6@cell.co.uk>
- NNTP-Posting-Host: daffy.willows.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0GoldB2 (Win95; I)
-
- Kai Chan wrote:
- >
- > main()
- > {
- > some_type1 **ptr;
- >
- > func1(ptr); /* is this right? */
- > func1(&ptr); /* or this? */
- > func1(**ptr); /* or this? */
- > func1(*ptr); /* or this? */
- >
- > }
- >
- > func1(some_type1 **ptr)
- > {
- > blar...
- > blar...
- > }
- >
-
-
- Technically func1(ptr) is right. However I'm not sure that it's really
- what you want to do. If what you want to do is to have a function assign
- the pointer then what you really want is:
-
- int func1 ( void **p, int x )
- {
- if ( *p = malloc ( x ) )
- return ( x );
- else
- return ( 0 );
- }
-
- int main ( void )
- {
-
- void *p;
-
- if ( func1 ( &p, 10 ) )
- free ( p );
-
- return ( 0 );
-
- }
-